using Godot;

namespace PlayerState
{
public partial class Roll : Node,StateNode
{
    public Player player;
    public Timer cdTimer;
    public bool isRollFinsihed;

    public override void _Ready()
    {
        player = GetNode<Player>("/root/Main/Player");

        cdTimer = GetNode<Timer>("CD");
    }

    public void OnCDTimeout()
    {        
        player.IsRoll = false;
    }

    public void OnRollFinished()
    {        
        if(player.AnimaPlayer.Animation=="roll")
        {
            cdTimer.Start();
            isRollFinsihed=true;
            player.CanAttack=true;
            player.ResumePlain();
        }
    }

    public void OnEnter()
    {
        player.AnimaPlayer.Animation = "roll";
        isRollFinsihed=false;
        
        GetNode<AudioStreamPlayer2D>("Music").Play();

        player.IsRoll=true;
        player.CanAttack=false;        
        player.EnterInvincible();
    }
    
    public void OnExit()
    {                               
    }

    public void OnUpdate(float delta)
    {        
        if(player.Health<=0)
            player.SwitchTo("dead");        
        else if(isRollFinsihed)
        {            
            if(player.IsRun())
                player.SwitchTo("Run");
            else
                player.SwitchTo("Idle");
        }
    }
}
}